var router = require('koa-router')();

/** 投资协议 start **/
router.post('/agreement/list',async (ctx, next)=>{
    let {
        page=1,
        size=10,
        type='',
    } = ctx.request.body;
    let count = await ctx.post('/admin/countAgreement',{type});
    let result = await ctx.post('/admin/listAgreement',{page,size,type});
    if(count.cd==0){
        result.total = count.data;
    }
    ctx.body = result;
});
//get
router.post('/agreement/get', async (ctx,next) => {
    let {id} = ctx.request.body;
    let result = await ctx.post('/admin/getAgreementById',{id});
    if(result.cd==0){
        delete result.data.create_id;
        delete result.data.created_at;
        delete result.data.update_id;
        delete result.data.updated_at;
    }
    ctx.body = result;
})
//保存
router.post('/agreement/save', async (ctx,next) => {
    let {agreement} = ctx.request.body;
    agreement.type = parseInt(agreement.type);
    agreement.status = parseInt(agreement.status);
    let result = null;
    if(agreement.id){
        result = await ctx.post('/admin/updateAgreement',{...agreement})
    }else{
       result = await ctx.post('/admin/insertAgreement',{...agreement})
    }
    ctx.body = result;
})
//删除
router.post('/agreement/delete' , async (ctx,next) => {
    let {id} = ctx.request.body;
    ctx.body = await ctx.post('/admin/deleteAgreementById',{id});
})
//修改状态
router.post('/agreement/updateAgreementStatus' , async (ctx,next) => {
    let {id} = ctx.request.body;
    ctx.body = await ctx.post('/admin/updateAgreementStatus' , {id});
})
/** 投资协议 end **/


export default router;
